$$.DomHelper = (function(){
	return {
		create: function(o){
			if($$.isDom(o)) return o;
			
			o = $$.put({
				tag: 'div'
				,id: $$.prefix + '-el-' + $$.seq()
			}, o);
			
			var dom = document.createElement(o.tag);
			dom.id = o.id;
			if(o.cls) dom.className = 'string' == typeof o.cls? o.cls : o.cls.join(' ');
			if(o.html) dom.innerHTML = o.html;
			if(o.style) $$.DomHelper.setStyle(dom, o.style);
			if(o.children) $$.DomHelper.append(dom, o.children);
			
			delete o.id; delete o.tag; delete o.cls; delete o.html;
			delete o.style; delete o.children;
			
			for(var i in o){
				dom.setAttribute(i, o[i]);
			}
			
			return dom;
		}
		,setStyle: function(dom, style){
			if('string' == typeof style){
				dom.setAttribute('style', style);
			}else{
				for(var i in style){
					$$.isIE? dom.style.i : dom.style[i] = style[i];
				}
			}
			return dom;
		}
		,append: function(dom, children){
			if(!$$.isArray(children)) children = [children];
			var child;
			for(var i = 0, len = children.length; i < len; ++i){
				child = $$.getDom(children[i]);
				dom.appendChild(child);
			}
			return dom;
			/*
			
			if($$.isEl(children)){
				children = children.dom;
			}
			
			if($$.isDom(children)){
				dom.appendChild(children);
				return dom;	
			}
			
			if($$.isObject(children)){
				var child = $$.DomHelper.create(children);
				if(children.children) $$.DomHelper.append(child, children.children);
				dom.appendChild(child);
				return dom;
			}
	
			
			return dom;*/
		}
		,insertBefore: function(parent, newDom, ref){
			newDom = $$.DomHelper.create(newDom);
			return parent.insertBefore(newDom, ref);
		}
		,insertAfter: function(parent, newDom, ref){
			if(ref) ref = ref.nextSibling;
			return $$.DomHelper.insertBefore(parent, newDom, ref);	
		}
		,insertAt: function(dom, index, newDom){
			index = index || 0;
			newDom = $$.DomHelper.create(newDom);
			return $$.DomHelper.insertBefore(dom, newDom, dom.children.item(index));
		}
		,update: function(dom, o){
			if($$.isString(o)){
				dom.innerHTML = o;
				return dom;	
			}
			
			o = $$.getDom(o);
			dom.innerHTML = '';
			$$.DomHelper.append(dom, o);
			return dom;	
		}
		,remove: function(dom){
			dom.parentNode.removeChild(dom);
			return this;
		}
		,getClass: function(){
			
		}
		,addClass: function(dom, cls){
			var oldCls = dom.className;
			oldCls = oldCls.split(' ');
			
			if($$.isString(cls)) cls = cls.splitWord();
			dom.className = oldCls.concat(cls).join(' ');
			
			return dom;
		}
		,removeClass: function(dom, cls){
			if($$.isString(cls)) cls = cls.trimAll();
			var regx = new RegExp(cls.replace(/ /g, '|'), g);
			
			var oldCls = dom.className;
			oldCls = oldCls.replace(regx, '');
			
			dom.className = oldCls;
			return dom;
		}
		,wrap: function(dom, wrap){
			var wrap = this.insertBefore(dom.parentNode, wrap, dom);
			wrap.appendChild(dom);
			return wrap;
		}
		,unWrap: function(dom){
			var wrap = dom.parentNode;
			this.insertBefore(wrap.parentNode, dom, wrap);
			this.remove(wrap);
			return dom;
		}
		,replace: function(dom, rep){
			rep = $$.getDom(rep);
			this.insertBefore(rep.parentNode, dom, rep);
			this.remove(rep);
			return dom;
		}
	};
})();